﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Data.GameData;

namespace GUIDialogs.Special_Gadgets
{
    class EnviromentalComboBox : ExtComboBox
    {
        /// <summary>
        /// A class to encapsulate the information shown in this specfic ComboBox
        /// </summary>
        #region EnviromentalComboItem
        private class EnviromentalComboItem
        {
            private string text;
            private SystemBodyEnviroment enviroment;


            public string Text
            {
                get { return text; }
                set { text = value; }
            }

            public SystemBodyEnviroment Enviroment
            {
                get { return enviroment; }
                set { enviroment = value; }
            }

            public EnviromentalComboItem(string t, SystemBodyEnviroment e)
            {
                text = t;
                enviroment = e;
            }

            public override string ToString()
            {
                return text;
            }
        }
        #endregion

        bool showAll;

        public EnviromentalComboBox()
        {
            showAll = true;
            Initialise();
        }

        #region Private Methods
        /// <summary>
        /// Fill the combobox with the correct values based on the showAll attribute
        /// </summary>
        private void Initialise()
        {
            this.Items.Add(new EnviromentalComboItem("Terrestial (T)", SystemBodyEnviroment.TYPE_T));
            this.Items.Add(new EnviromentalComboItem("Super-Terrestial (ST)", SystemBodyEnviroment.TYPE_ST));

            if (showAll)
            {
                this.Items.Add(new EnviromentalComboItem("Gas Giant (G)", SystemBodyEnviroment.TYPE_G));
                this.Items.Add(new EnviromentalComboItem("Ice Planet (I)", SystemBodyEnviroment.TYPE_I));
                this.Items.Add(new EnviromentalComboItem("Venus-like (V)", SystemBodyEnviroment.TYPE_V));
                this.Items.Add(new EnviromentalComboItem("Ice Planetoid (O1)", SystemBodyEnviroment.TYPE_O1));
                this.Items.Add(new EnviromentalComboItem("Rocky Planetoid (O2)", SystemBodyEnviroment.TYPE_O2));
                this.Items.Add(new EnviromentalComboItem("Hot Planetoid (O3)", SystemBodyEnviroment.TYPE_O3));
            }
            this.SelectedIndex = 0;
        }
        #endregion

        #region Properties
        /// <summary>
        /// Property for the showAll attribute, on changing it resets the combobox entries
        /// </summary>
        public bool ShowAll
        {
            get { return showAll; }
            set
            {
                showAll = value;

                this.Items.Clear();
                Initialise();
            }
        }

        public SystemBodyEnviroment SelectedEnviroment
        {
            get
            {
                EnviromentalComboItem item = this.SelectedItem as EnviromentalComboItem;
                if (item == null)
                    return SystemBodyEnviroment.TYPE_T;

                return item.Enviroment;
            }
            set
            {
                switch (value)
                {
                    default:
                    case SystemBodyEnviroment.TYPE_T:  this.SelectedIndex = 0; break;
                    case SystemBodyEnviroment.TYPE_ST: this.SelectedIndex = 1; break;
                    case SystemBodyEnviroment.TYPE_G:  this.SelectedIndex = 2; break;
                    case SystemBodyEnviroment.TYPE_I:  this.SelectedIndex = 3; break;
                    case SystemBodyEnviroment.TYPE_V:  this.SelectedIndex = 4; break;
                    case SystemBodyEnviroment.TYPE_O1: this.SelectedIndex = 5; break;
                    case SystemBodyEnviroment.TYPE_O2: this.SelectedIndex = 6; break;
                    case SystemBodyEnviroment.TYPE_O3: this.SelectedIndex = 7; break;
                }
            }
        }
        #endregion
    }
}
